package com.example.sy2.demos.web.controller;

import com.example.sy2.demos.web.entity.Course;
import com.example.sy2.demos.web.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courses")
public class CourseController {
    @Autowired
    private CourseService courseService;

    @GetMapping("/listAll")
    public ResponseEntity<List<Course>> listAll() {
        return ResponseEntity.ok(courseService.listAllCourses());
    }

    @GetMapping("/getById/{courseId}")
    public ResponseEntity<Course> getById(@PathVariable Long courseId) {
        return ResponseEntity.ok(courseService.getCourseById(courseId));
    }

    @PostMapping("/add")
    public ResponseEntity<Void> add(@RequestBody Course course) {
        courseService.addCourse(course);
        return ResponseEntity.ok().build();
    }
}

